package Strategy;

/**
 * @ProjectName: 23种设计模式
 * @Package: Strategy
 * @ClassName: Sorter
 * @Author: renhan
 * @Description:
 * @Date: 2020/11/10 16:44
 * @Version: 1.0
 */
public class Sorter<T> {
    public  void sort (T[] arr, Comparator<T> comparator) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minPos = i;

            for (int j = i + 1; j < arr.length; j ++) {
                minPos = comparator.compare(arr[j], arr[minPos]) == -1 ? j : minPos;
            }
            swop (arr, i, minPos);
        }
    }

    private  void swop(T[] arr, int i, int j) {
        T temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }


}
